<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:include="include :: header('修改小说')"/>
</head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
    <form class="form-horizontal m" id="form-novel-edit" th:object="${novel}">
        <input name="novelId" th:field="*{novelId}" type="hidden">
        <div class="col-xs-12">
            <div class="form-group">
                <label class="col-sm-3 control-label is-required">作者：</label>
                <div class="col-sm-8">
                    <select name="authorId" id="authorId" class="form-control" required>
                        <!-- 商品选项将通过 JavaScript 动态填充 -->
                        <option th:each="author:${authors}" th:value="${author.authorId}" th:text="${author.name}" th:selected="${novel.authorId == author.authorId}"></option>
                    </select>
                </div>
            </div>
        </div>
        <div class="col-xs-12">
            <div class="form-group">
                <label class="col-sm-3 control-label is-required">分类：</label>
                <div class="col-sm-8">
                    <select name="categoryId" id="categoryId" class="form-control" required>
                        <!-- 商品选项将通过 JavaScript 动态填充 -->
                        <option th:each="category:${categoryList}" th:value="${category.id}" th:text="${category.name}" th:selected="${novel.categoryId == category.id}"></option>
                    </select>
                </div>
            </div>
        </div>
        <div class="col-xs-12">
            <div class="form-group">
                <label class="col-sm-3 control-label is-required">小说标题：</label>
                <div class="col-sm-8">
                    <input name="title" th:field="*{title}" class="form-control" type="text" required>
                </div>
            </div>
        </div>
        <div class="col-xs-12">
            <div class="form-group">
                <label class="col-sm-3 control-label">图片：</label>
                <!--                 onclick="$.triggerFileInput()"-->
                <div class="UploadImg">  <!-- 为整个区域添加点击事件 -->
                    <div class="imgList" id="imgList">
                        <!-- 这里用于显示已上传的图片或加载状态 -->
                        <img th:if="${novel.imgUrl}" th:src="${novel.imgUrl}" width="100" height="100" border-radius="10" border="1px solid #d9d9d9" />
                    </div>
                </div>
                <input type="file" id="fileInput" style="display: none;"/>
                <!-- 隐藏的文件输入元素，并绑定 onchange 事件 -->
                <input name="imgUrl" id="imgUrl" th:field="*{imgUrl}" class="form-control" type="hidden">
            </div>
        </div>
        <div class="col-xs-12">
            <div class="form-group">
                <label class="col-sm-3 control-label">小说描述：</label>
                <div class="col-sm-8">
                    <textarea name="description" class="form-control">[[*{description}]]</textarea>
                </div>
            </div>
        </div>
        <div class="col-xs-12">
            <div class="form-group">
                <label class="col-sm-3 control-label">价格：</label>
                <div class="col-sm-8">
                    <input name="price" th:field="*{price}" class="form-control" type="text">
                </div>
            </div>
        </div>
        <div class="col-xs-12">
            <div class="form-group">
                <label class="col-sm-3 control-label">库存：</label>
                <div class="col-sm-8">
                    <input name="stock" th:field="*{stock}" class="form-control" type="text">
                </div>
            </div>
        </div>
    </form>
</div>
<th:block th:include="include :: footer"/>
<script th:inline="javascript">
    var prefix = ctx + "system/novel";
    var uploadUrl = ctx + "common/upload";
    $(document).ready(function() {
        $("#form-novel-edit").validate({
            focusCleanup: true
        });

        // 当页面加载完成时，执行以下代码
        $.fileUpload.init();
    });

    function submitHandler() {
        if ($.validate.form()) {
            $.operate.save(prefix + "/edit", $('#form-novel-edit').serialize());
        }
    }
</script>
</body>
</html>